project(myrender VERSION 0.1 LANGUAGES CXX)

set(PROJECT_HEADERS *.h)

set(PROJECT_SOURCES
    main.cpp
    widget.cpp widget.h

    geometry.h
    mathengine.h
    transform.h transform.cpp
    objfile.h objfile.cpp
    model.h model.cpp
    color.h

    rasterizer.h rasterizer.cpp
    tgaimage.h tgaimage.cpp

    init.h init.cpp
    utils.h
    our_gl.h our_gl.cpp
    ishader.h
    shader.h

    rasterwidget.h rasterwidget.cpp
    rendercontext.h rendercontext.cpp
)

set(PROJECT_RESOURCES
    widget.ui
)

# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(myrender MANUAL_FINALIZATION ${PROJECT_SOURCES} ${PROJECT_RESOURCES})

# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
    add_executable(myrender ${PROJECT_SOURCES} ${PROJECT_RESOURCES})
endif()

### enable AddressSanitizer for target
# target_compile_options(myrender PRIVATE -fsanitize=address)
# target_link_options(myrender PRIVATE -fsanitize=address)

target_link_libraries(myrender PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

### for test, added by martin
add_library(libmyrender SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES})
target_link_libraries(libmyrender PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.myrender)
endif()
set_target_properties(myrender PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS myrender
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(myrender)
endif()

